package special_tree;

import java.util.Map;

import compiler.CompilerException;

import code.CodeList;
import code.Opcode;
import code.TargetCode;
import lexer.Token;
import lexer.TokenType;
import tree.ClassScope;
import tree.IdentifierScope;
import tree.MethodScope;
import tree.MyTree;
import tree.NamingException;
import tree.Tree;

public class ProgramTree extends MyTree {

	@Deprecated
	private Tree mainObject;
	@Deprecated
	private Tree mainMethodCall;
	
	public ProgramTree(Token[] mainClassName,
			Map<String, Tree> importFiles, Tree... classes) {
		super(new Token(-1, -1, TokenType.MAINCLASS, ""), classes);
	}

	/* (non-Javadoc)
	 * @see tree.MyTree#generateProgramCode(code.TargetCode)
	 */
	@Override
	@Deprecated
	public void generateProgramCode(TargetCode targetCode) throws CompilerException {
		for (int i = 0; i<getOperands(); i++) {
			getOperand(i).generateProgramCode(targetCode);
		}
		CodeList mainCode = new CodeList();	
		mainMethodCall.generateCode(mainCode);
		mainCode.generateCode(Opcode.HALT);
		targetCode.putMainCode(mainCode);
	}

	/* (non-Javadoc)
	 * @see tree.MyTree#analyzeNames(tree.IdentifierScope, tree.MethodScope, tree.ClassScope)
	 */
	@Override
	@Deprecated
	public void analyzeNames(IdentifierScope identScope,
			MethodScope methodScope, ClassScope classScope)
			throws NamingException {
		super.analyzeNames(identScope, methodScope, classScope);
		mainObject.analyzeNames(identScope, methodScope, classScope);
		mainMethodCall.analyzeNames(identScope, methodScope, classScope);
	}

}
